<!DOCTYPE html>
<html lang="zh-cn" xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui/css/layui.css" />
    <script src="https://www.layuicdn.com/layui/layui.js"></script>
</head>
<body>
<div class="site-text" style="margin: 5%;">
    <form class="layui-form layui-form-pane" onsubmit="return false" th:object="${student}">
        <input name="id" th:field="*{id}"  type="hidden">
        <div class="layui-form-item">
            <div class="layui-form-item">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" name="name" th:field="*{name}" lay-verify="required">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block">
                    <input type="radio" name="sex" th:field="*{sex}" value="0" title="男" checked>
                    <input type="radio" name="sex" th:field="*{sex}" value="1" title="女">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">年龄</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" name="age" th:field="*{age}" lay-verify="required|number">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">出生年份</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" id="time" name="time" th:field="*{time}" placeholder="yyyy-MM-dd" lay-verify="required|date">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" class="layui-textarea" name="remarks" th:field="*{remarks}" lay-verify="required"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="updateStudent">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </form>
    <script>
        layui.use(['element', 'table', 'form', 'jquery','laydate'], function(){
            var form = layui.form;
            var $ = layui.jquery;
            var table = layui.table;
            //监听提交
            form.on('submit(updateStudent)', function(data){
                $.ajax({
                    url: "../student/updateStudent",
                    type: "POST",
                    data: data.field,
                    success: function (data) {
                        if (data.status === 200) {
                            layer.alert(data.data, { shift: -1 }, function () {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                //关闭当前frame
                                parent.layer.close(index);
                                //修改成功后刷新父界面
                                window.parent.location.reload();
                            });
                        } else if (data.status === 201) {
                            layer.msg(data.data);
                        }
                    },
                    error: function (xhr, status, error) {
                        layer.msg("网络出错")
                    }
                });
                return false;
            });
            /**
             * 时间插件
             **/
            var laydate = layui.laydate;
            laydate.render({
                elem: '#time'
            });
        });
    </script>
</div>
</body>
</html>